<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: ActiveRecord::ConnectionAdapters::ConnectionHandler</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">ActiveRecord::ConnectionAdapters::ConnectionHandler</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool_rb.html">
                vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="ConnectionHandler.html">ConnectionHandler</a> is a collection of
<a href="ConnectionPool.html">ConnectionPool</a> objects. It is used for
keeping separate connection pools for ActiveRecord models that connect to
different databases.
</p>
<p>
For example, suppose that you have 5 models, with the following hierarchy:
</p>
<pre>
 |
 +-- Book
 |    |
 |    +-- ScaryBook
 |    +-- GoodBook
 +-- Author
 +-- BankAccount
</pre>
<p>
Suppose that Book is to connect to a separate database (i.e. one other than
the default database). Then Book, ScaryBook and GoodBook will all use the
same connection pool. Likewise, Author and BankAccount will use the same
connection pool. However, the connection pool used by Author/BankAccount is
not the same as the one used by Book/ScaryBook/GoodBook.
</p>
<p>
Normally there is only a single <a
href="ConnectionHandler.html">ConnectionHandler</a> instance, accessible
via ActiveRecord::Base.connection_handler. ActiveRecord models use this to
determine that connection pool that they should use.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M001572">clear_active_connections!</a>&nbsp;&nbsp;
      <a href="#M001574">clear_all_connections!</a>&nbsp;&nbsp;
      <a href="#M001573">clear_reloadable_connections!</a>&nbsp;&nbsp;
      <a href="#M001575">connected?</a>&nbsp;&nbsp;
      <a href="#M001570">connection_pools</a>&nbsp;&nbsp;
      <a href="#M001571">establish_connection</a>&nbsp;&nbsp;
      <a href="#M001569">new</a>&nbsp;&nbsp;
      <a href="#M001576">remove_connection</a>&nbsp;&nbsp;
      <a href="#M001577">retrieve_connection_pool</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M001569" class="method-detail">
        <a name="M001569"></a>

        <div class="method-heading">
          <a href="#M001569" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(pools = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001569-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001569-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 287</span>
287:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">pools</span> = {})
288:         <span class="ruby-ivar">@connection_pools</span> = <span class="ruby-identifier">pools</span>
289:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M001572" class="method-detail">
        <a name="M001572"></a>

        <div class="method-heading">
          <a href="#M001572" class="method-signature">
          <span class="method-name">clear_active_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns any connections in use by the current thread back to the pool, and
also returns connections to the pool cached by threads that are no longer
alive.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001572-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001572-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 302</span>
302:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_active_connections!</span>
303:         <span class="ruby-ivar">@connection_pools</span>.<span class="ruby-identifier">each_value</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pool</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pool</span>.<span class="ruby-identifier">release_connection</span> }
304:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001574" class="method-detail">
        <a name="M001574"></a>

        <div class="method-heading">
          <a href="#M001574" class="method-signature">
          <span class="method-name">clear_all_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001574-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001574-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 311</span>
311:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_all_connections!</span>
312:         <span class="ruby-ivar">@connection_pools</span>.<span class="ruby-identifier">each_value</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pool</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pool</span>.<span class="ruby-identifier">disconnect!</span> }
313:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001573" class="method-detail">
        <a name="M001573"></a>

        <div class="method-heading">
          <a href="#M001573" class="method-signature">
          <span class="method-name">clear_reloadable_connections!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Clears the cache which maps classes
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001573-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001573-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 307</span>
307:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">clear_reloadable_connections!</span>
308:         <span class="ruby-ivar">@connection_pools</span>.<span class="ruby-identifier">each_value</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">pool</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pool</span>.<span class="ruby-identifier">clear_reloadable_connections!</span> }
309:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001575" class="method-detail">
        <a name="M001575"></a>

        <div class="method-heading">
          <a href="#M001575" class="method-signature">
          <span class="method-name">connected?</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if a connection that&#8216;s accessible to this class has
already been opened.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001575-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001575-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 331</span>
331:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connected?</span>(<span class="ruby-identifier">klass</span>)
332:         <span class="ruby-identifier">conn</span> = <span class="ruby-identifier">retrieve_connection_pool</span>(<span class="ruby-identifier">klass</span>)
333:         <span class="ruby-identifier">conn</span> <span class="ruby-value">? </span><span class="ruby-identifier">conn</span>.<span class="ruby-identifier">connected?</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">false</span>
334:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001570" class="method-detail">
        <a name="M001570"></a>

        <div class="method-heading">
          <a href="#M001570" class="method-signature">
          <span class="method-name">connection_pools</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001570-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001570-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 291</span>
291:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connection_pools</span>
292:         <span class="ruby-ivar">@connection_pools</span> <span class="ruby-operator">||=</span> {}
293:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001571" class="method-detail">
        <a name="M001571"></a>

        <div class="method-heading">
          <a href="#M001571" class="method-signature">
          <span class="method-name">establish_connection</span><span class="method-args">(name, spec)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001571-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001571-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 295</span>
295:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">establish_connection</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">spec</span>)
296:         <span class="ruby-ivar">@connection_pools</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-constant">ConnectionAdapters</span><span class="ruby-operator">::</span><span class="ruby-constant">ConnectionPool</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">spec</span>)
297:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001576" class="method-detail">
        <a name="M001576"></a>

        <div class="method-heading">
          <a href="#M001576" class="method-signature">
          <span class="method-name">remove_connection</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Remove the connection for this class. This will close the active connection
and the defined connection (if they exist). The result can be used as an
argument for <a
href="ConnectionHandler.html#M001571">establish_connection</a>, for easily
re-establishing the connection.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001576-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001576-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 340</span>
340:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_connection</span>(<span class="ruby-identifier">klass</span>)
341:         <span class="ruby-identifier">pool</span> = <span class="ruby-ivar">@connection_pools</span>[<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">name</span>]
342:         <span class="ruby-ivar">@connection_pools</span>.<span class="ruby-identifier">delete_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">pool</span> }
343:         <span class="ruby-identifier">pool</span>.<span class="ruby-identifier">disconnect!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pool</span>
344:         <span class="ruby-identifier">pool</span>.<span class="ruby-identifier">spec</span>.<span class="ruby-identifier">config</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pool</span>
345:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M001577" class="method-detail">
        <a name="M001577"></a>

        <div class="method-heading">
          <a href="#M001577" class="method-signature">
          <span class="method-name">retrieve_connection_pool</span><span class="method-args">(klass)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M001577-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M001577-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 347</span>
347:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">retrieve_connection_pool</span>(<span class="ruby-identifier">klass</span>)
348:         <span class="ruby-identifier">pool</span> = <span class="ruby-ivar">@connection_pools</span>[<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">name</span>]
349:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">pool</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pool</span>
350:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">klass</span>
351:         <span class="ruby-identifier">retrieve_connection_pool</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">superclass</span>
352:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>